<?php

class DefaultController extends Controller_index
{
	public function actionIndex()
	{
            $model=new WxJoin();
            
            //如果前台开启ajax则取消此注释
	    $this->performAjaxValidation($model);

            if(isset($_POST['WxJoin'])){
                 $model->attributes=$_POST['WxJoin'];
                if(!empty($model->phone)){
                    
                    if(is_numeric($model->phone)){
                        $model_save= WxJoin::model()->find("phone=".$model->phone);
                        if(!isset($model_save)){
                            $this->redirect('http://www.shinho.com.cn/qz',301);
                        }else{
                            $this->redirect(array('default/message','id'=>$model_save->id));
                        }
                     }
                     else{
                            //$error['message']="*手机号至能填写数字";
                     }
                }else{
                            //$error['message']="*手机号不能为空";
                }
                 
            }

                $this->render('index',array(
                       'model'=>$model,
               ));
	}
        public function actionMessage($id)
	{
           
                 $model= WxJoin::model()->findByPk($id);

                if(isset($_POST['WxJoin'])){
                       
                 $model->attributes=$_POST['WxJoin'];
                 $model_save= WxJoin::model()->findByPk($id);
                 $model_save->right_float=1;
                 $model_save->right_time=date('y-m-d h:i:s',time());

                 if($model_save->save()){
                     $this->redirect(array('default/message','id'=>$model_save->id));
                 }else{
                      
                     //$this->redirect(array('default/message','id'=>$model_save->id));
                 }
                 
                 }

		 $this->render('message',array(
                       'model'=>$model,
               ));
	}
        
        public function actionAdd()
        {
         if($model_save->save()){
                          Yii::app()->user->setFlash('success','感谢您的提交！');
                          $this->redirect(array('default/outsign','id'=>$model2->item_id));
                   } 
             
        }
        
       /**
	 * Performs the AJAX validation.
	 * @param WxJoin $model the model to be validated
	 */
	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='wx-join-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}
        

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}